﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using ShapeDemo.UC.WinProp;
using System.Windows;
using System.Windows.Input;

namespace ShapeDemo
{
    public class EllipseDrawer
    {
        private Canvas ellipseCanvas;
        private List<ASPNETX_WPFEllipse> lstEllipse;
        private WinPropEllipse winEllipseProp;
        private WinPropCommon winCommonProp;

        ASPNETX_WPFEllipse elBody;
        TMouse MouseType;

        bool IsEllipseInDrawing = false;

        public EllipseDrawer(Canvas canvasContent, List<ASPNETX_WPFEllipse> lstShape, WinPropEllipse winShapeProp, WinPropCommon winProp)
        {
            ellipseCanvas = canvasContent;
            lstEllipse = lstShape;
            winEllipseProp = winShapeProp;
            winCommonProp = winProp;

            MouseType = TMouse.Drawing;

            ellipseCanvas.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(ellipseCanvas_MouseLeftButtonDown);
            ellipseCanvas.MouseMove += new System.Windows.Input.MouseEventHandler(ellipseCanvas_MouseMove);
        }

        public void Draw()
        { 
            
        }

        #region 画圆
        private void ellipseCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (MouseType == TMouse.Drawing)
            {
                if (IsEllipseInDrawing == false)
                {
                    elBody = ResourceCenter.NewEllipse();

                    ellipseCanvas.Children.Add(elBody.EllipseBody);

                    elBody.P1 = e.GetPosition(ellipseCanvas);
                    IsEllipseInDrawing = true;

                    return;
                }
                if (IsEllipseInDrawing == true)
                {
                    elBody.P2 = e.GetPosition(ellipseCanvas);
                    IsEllipseInDrawing = false;

                    //添加基本属性
                    elBody.CommonProperty.Index = winCommonProp.tbIndex.Text;
                    elBody.CommonProperty.Content = winCommonProp.tbContent.Text;

                    lstEllipse.Add(elBody);

                    //BindListBox();

                    return;
                }
            }
        }

        private void ellipseCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseType == TMouse.Drawing)
            {
                if (IsEllipseInDrawing == true)
                {
                    Point p = e.GetPosition(ellipseCanvas);
                    elBody.P2 = p;

                    elBody.EllipseBody.SetValue(Canvas.LeftProperty, elBody.Left);
                    elBody.EllipseBody.SetValue(Canvas.TopProperty, elBody.Top);
                    elBody.EllipseBody.Width = elBody.Width;
                    elBody.EllipseBody.Height = elBody.Height;

                    winEllipseProp.X = elBody.Left;
                    winEllipseProp.Y = elBody.Top;

                    winEllipseProp.Width = elBody.Width;
                    winEllipseProp.Height = elBody.Height;
                }
            }
        }
        #endregion
    }
}
